package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.ISystemNoticeDao;
import com.ctg.itrdc.imageconsole.data.entity.SystemNotice;
import com.ctg.itrdc.paspsdk.common.entity.PageInfo;
import com.ctg.itrdc.paspsdk.common.utils.type.StringUtils;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;
import com.ctg.itrdc.paspsdk.data.entity.ClassInfoUtils;

@Component("systemNoticeDao")
public class SystemNoticeDaoImpl extends BaseDaoImpl implements ISystemNoticeDao {

	public PageInfo<SystemNotice> jdbcFindPageInfo(SystemNotice systemNotice, int currentPage, int perPageNum
			, boolean isDockerManager) {
		String columnsName = ClassInfoUtils.getColumnsName(SystemNotice.class);
		String tableName = ClassInfoUtils.getTableName(SystemNotice.class);
		StringBuilder sql = new StringBuilder(" SELECT ");
		sql.append(columnsName).append(" FROM ").append(tableName).append(" A WHERE 1=1 ");

		List<Object> params = new ArrayList<Object>();

		if (StringUtils.isNotEmpty(systemNotice.getNoticeType())) {
			sql.append(" AND NOTICE_TYPE LIKE ? ");
			params.add("%" + systemNotice.getNoticeType() + "%");
		}
		if (StringUtils.isNotEmpty(systemNotice.getNoticeState())) {
			sql.append(" AND NOTICE_STATE = ? ");
			params.add(systemNotice.getNoticeState());
		}
		if (StringUtils.isNotEmpty(systemNotice.getNoticeContent())) {
			sql.append(" AND NOTICE_CONTENT LIKE ? ");
			params.add("%" + systemNotice.getNoticeContent() + "%");
		}
		if (!isDockerManager && null != systemNotice.getNoticeUserId()) {
			sql.append(" AND NOTICE_USER_ID = ? ");
			params.add(systemNotice.getNoticeUserId());
		}
		sql.append(" ORDER BY NOTICE_TIME DESC");
		return (PageInfo<SystemNotice>) this.jdbcFindPageInfo(sql.toString(), SystemNotice.class, params, currentPage,
				perPageNum, true);
	}

}
